//
//  JLCommon.m
//  JLStyleApp
//
//  Created by LvJianfeng on 15/8/21.
//  Copyright (c) 2015年 JLStyle. All rights reserved.
//

#import "JLCommon.h"
@implementation JLCommon
+ (JLCommon *)shareManager{
    __strong static JLCommon *sharedManager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedManager = [[JLCommon alloc] init];
    });
    return sharedManager;
}

- (NSArray *)get_Provinces{
    NSMutableArray *dataArray = [[NSMutableArray alloc] init];
    FMDatabase *db = [FMDatabase databaseWithPath:[JLInitialize databaseCityFilePath]];
    if (db) {
        [db open];
        FMResultSet *rs = [db executeQuery:@"SELECT * FROM JL_PROVINCES"];
        while ([rs next]) {
            City *city = [City fromCursor:rs];
            [dataArray addObject:city];
        }
    }
    return dataArray;
}

- (NSArray *)get_CityByProvinces:(int)pid{
    NSMutableArray *dataArray = [[NSMutableArray alloc] init];
    FMDatabase *db = [FMDatabase databaseWithPath:[JLInitialize databaseCityFilePath]];
    if (db) {
        [db open];
        FMResultSet *rs = [db executeQuery:@"SELECT * FROM JL_CITY WHERE PID = ?",[NSString stringWithFormat:@"%d",pid]];
        while ([rs next]) {
            City *city = [City fromCursorCity:rs];
            [dataArray addObject:city];
        }
    }
    return dataArray;
}
@end
